package 启蒙阶段;

/**
 * 创建人：刘源江
 * 类描述：数组
 * 创建时间：2022/3/24 23:08
 **/

public class demo05数组 {
    public static void main(String[] args) {
        //数组的三种写法
        System.out.println("-----------------------------------");
        System.out.println("数组的三种写法:");
        int[] arr = new int[3]; //新建一个整形数组，长度为3，默认指都是0
        System.out.println("第1个数:" + arr[0] + '\t' + "第2个数:" + arr[1] + '\t' + "第3个数:" + arr[2]);

        int[] arr2 = new int[]{1 , 2 , 3}; //新建一个数组，并给其赋值1，2，3
        for (int i = 0; i <= arr2.length - 1 ; i++) {
            int j = i + 1;
            System.out.print("第" + j + "个数:" + arr2[i] + '\t');
        }
        System.out.println();

        int[] arr3 = {4 , 5 , 6}; //新建一个数组，并给其赋值4，5，6
        for (int i = 0; i <= arr3.length - 1 ; i++) {
            int j = i + 1;
            System.out.print("第" + j + "个数:" + arr3[i] + '\t');
        }
        System.out.println();

        System.out.println("-----------------------------------");
        System.out.println("数组的倒叙和倒叙遍历");
        //数组的倒叙遍历
        int[] arr4 = {1 , 2 , 3 , 4 , 5 ,  6 , 7 , 8 , 9};
        System.out.print("数组倒叙遍历:");
        for (int i = arr4.length - 1; i >= 0 ; i--) {
            System.out.print(arr4[i]);
        }
        System.out.println();

        //数组的倒叙
        int[] arr5 = {1 , 0 , 0 , 8 , 6};
        System.out.print("数组:");
        for (int i = 0; i < arr5.length ; i++) {
            System.out.print(arr5[i]);
        }

        System.out.print("  ");
        for (int i = 0; i < arr5.length/2 ; i++) {
            int ta = arr5[i];
            arr5[i] = arr5[arr5.length - 1 - i];
            arr5[arr5.length - 1 - i] = ta;
        }
        System.out.print("数组倒叙:");
        for (int i = 0; i <= arr5.length - 1 ; i++) {
            System.out.print(arr5[i]);
        }
        System.out.println();
        System.out.println("-----------------------------------");

        //二维数组,了解即可
        int[] [] arrTwo = new int[3][2];// 给定空间，在赋值
    }
}
